home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Sound / MusicIn / encoder.h < prev    next >
C/C++ Source or Header  |  1997-09-23  |  16KB  |  371 lines

  1. /**********************************************************************
  2. Copyright (c) 1991 MPEG/audio software simulation group, All Rights Reserved
  3. encoder.h
  4. **********************************************************************/
  5. /**********************************************************************
  6.  * MPEG/audio coding/decoding software, work in progress              *
  7.  *   NOT for public distribution until verified and approved by the   *
  8.  *   MPEG/audio committee.  For further information, please contact   *
  9.  *   Davis Pan, 508-493-2241, e-mail: pan@gauss.enet.dec.com          *
  10.  *                                                                    *
  11.  * VERSION 3.5                                                       *
  12.  *   changes made since last update:                                  *
  13.  *   date   programmers         comment                               *
  14.  * 2/25/91  Doulas Wong,        start of version 1.0 records          *
  15.  *          Davis Pan                                                 *
  16.  * 5/10/91  W. Joseph Carter    Reorganized & renamed all ".h" files  *
  17.  *                              into "common.h" and "encoder.h".      *
  18.  *                              Ported to Macintosh and Unix.         *
  19.  *                              Added function prototypes for more    *
  20.  *                              rigorous type checking.               *
  21.  * 27jun91  dpwe (Aware)        moved "alloc_*" types, pros to common *
  22.  *                              Use ifdef PROTO_ARGS for prototypes   *
  23.  *                              prototypes reflect frame_params struct*
  24.  * 7/10/91  Earle Jennings      Conversion of all floats to FLOAT     *
  25.  * 10/3/91  Don H. Lee          implemented CRC-16 error protection   *
  26.  *                              Additions and revisions are marked    *
  27.  *                              with "dhl" for clarity                *
  28.  * 2/11/92  W. Joseph Carter    Ported new code to Macintosh.  Most   *
  29.  *                              important fixes involved changing     *
  30.  *                              16-bit ints to long or unsigned in    *
  31.  *                              bit alloc routines for quant of 65535 *
  32.  *                              and passing proper function args.     *
  33.  *                              Removed "Other Joint Stereo" option   *
  34.  *                              and made bitrate be total channel     *
  35.  *                              bitrate, irrespective of the mode.    *
  36.  *                              Fixed many small bugs & reorganized.  *
  37.  *                              Modified some function prototypes.    *
  38.  * 7/27/92  Masahiro Iwadare    FFT modifications for Layer 3         *
  39.  * 8/3/92   Mike Li             removed declaration _stklen for DOS.  *
  40.  * 9/22/92  jddevine@aware.com  Fix protos for _scale_factor_calc()   *
  41.  **********************************************************************/
  42.  
  43. /***********************************************************************
  44. *
  45. *  Encoder Include Files
  46. *
  47. ***********************************************************************/
  48.  
  49. /***********************************************************************
  50. *
  51. *  Encoder Definitions
  52. *
  53. ***********************************************************************/
  54.  
  55. /* General Definitions */
  56.  
  57. /* Default Input Arguments (for command line control) */
  58.  
  59. #define DFLT_LAY        2      /* default encoding layer is II */
  60. #define DFLT_MOD        's'    /* default mode is stereo */
  61. #define DFLT_PSY        2      /* default psych model is 2 */
  62. #define DFLT_SFQ        44.1   /* default input sampling rate is 44.1 kHz */
  63. #define DFLT_BRT        128    /* default total output bitrate is 384 kbps */
  64. #define DFLT_EMP        'n'    /* default de-emphasis is none */
  65. #define DFLT_EXT        ".mpg" /* default output file extension */
  66.  
  67. #define FILETYPE_ENCODE 'TEXT'
  68. #define CREATOR_ENCODE  'MpgD'
  69.  
  70. /* This is the smallest MNR a subband can have before it is counted
  71.    as 'noisy' by the logic which chooses the number of JS subbands */
  72.  
  73. #define NOISY_MIN_MNR   0.0
  74.  
  75. /* Psychacoustic Model 1 Definitions */
  76.  
  77. #define CB_FRACTION     0.33
  78. #define MAX_SNR         1000
  79. #define NOISE           10
  80. #define TONE            20
  81. #define DBMIN           -200.0
  82. #define LAST            -1
  83. #define STOP            -100
  84. #define POWERNORM       90.3090 /* = 20 * log10(32768) to normalize */
  85.                                 /* max output power to 96 dB per spec */
  86.  
  87. /* Psychoacoustic Model 2 Definitions */
  88.  
  89. #define LOGBLKSIZE      10
  90. #define BLKSIZE         1024
  91. #define HBLKSIZE        513
  92. #define CBANDS          63
  93. #define LXMIN           32.0
  94.  
  95. /***********************************************************************
  96. *
  97. *  Encoder Type Definitions
  98. *
  99. ***********************************************************************/
  100.  
  101. /* Psychoacoustic Model 1 Type Definitions */
  102.  
  103. typedef int        IFFT2[FFT_SIZE/2];
  104. typedef int        IFFT[FFT_SIZE];
  105. typedef double     D9[9];
  106. typedef double     D10[10];
  107. typedef double     D640[640];
  108. typedef double     D1408[1408];
  109. typedef double     DFFT2[FFT_SIZE/2];
  110. typedef double     DFFT[FFT_SIZE];
  111. typedef double     DSBL[SBLIMIT];
  112. typedef double     D2SBL[2][SBLIMIT];
  113.  
  114. typedef struct {
  115.         int        line;
  116.         double     bark, hear, x;
  117. } g_thres, *g_ptr;
  118.  
  119. typedef struct {
  120.         double     x;
  121.         int        type, next, map;
  122. } mask, *mask_ptr;
  123.  
  124. /* Psychoacoustic Model 2 Type Definitions */
  125.  
  126. typedef int        ICB[CBANDS];
  127. typedef int        IHBLK[HBLKSIZE];
  128. typedef FLOAT      F32[32];
  129. typedef FLOAT      F2_32[2][32];
  130. typedef FLOAT      FCB[CBANDS];
  131. typedef FLOAT      FCBCB[CBANDS][CBANDS];
  132. typedef FLOAT      FBLK[BLKSIZE];
  133. typedef FLOAT      FHBLK[HBLKSIZE];
  134. typedef FLOAT      F2HBLK[2][HBLKSIZE];
  135. typedef FLOAT      F22HBLK[2][2][HBLKSIZE];
  136. typedef double     DCB[CBANDS];
  137.  
  138. /***********************************************************************
  139. *
  140. *  Encoder Function Prototype Declarations
  141. *
  142. ***********************************************************************/
  143.  
  144. /* The following functions are in the file "musicin.c" */
  145.  
  146. #ifdef        PROTO_ARGS
  147. extern void   obtain_parameters(frame_params*, int*, unsigned long*,
  148.                            char[MAX_NAME_SIZE], char[MAX_NAME_SIZE]);
  149. extern void   parse_args(int, char**, frame_params*, int*, unsigned long*,
  150.                            char[MAX_NAME_SIZE], char[MAX_NAME_SIZE]);
  151. extern void   print_config(frame_params*, int*, unsigned long*,
  152.                            char[MAX_NAME_SIZE], char[MAX_NAME_SIZE]);
  153. void   usage(void);
  154. extern void   aiff_check(char*, IFF_AIFF*);
  155. #else
  156. extern void   obtain_parameters();
  157. extern void   parse_args();
  158. extern void   print_config();
  159. void   usage();
  160. extern void   aiff_check();
  161. #endif
  162.  
  163. /* The following functions are in the file "encode.c" */
  164.  
  165. #ifdef        PROTO_ARGS
  166. extern unsigned long    read_samples(FILE*, short[2304], unsigned long,
  167.                            unsigned long);
  168. extern unsigned long    get_audio(FILE*, short[2][1152], unsigned long,
  169.                            int, int);
  170. extern void   read_ana_window(double[HAN_SIZE]);
  171. extern void   window_subband(short**, double[HAN_SIZE], int);
  172. extern void   create_ana_filter(double[SBLIMIT][64]);
  173. extern void   filter_subband(double[HAN_SIZE], double[SBLIMIT]);
  174. extern void   encode_info(frame_params*, Bit_stream_struc*);
  175. extern double mod(double);
  176. extern void   I_combine_LR(double[2][3][SCALE_BLOCK][SBLIMIT],
  177.                            double[3][SCALE_BLOCK][SBLIMIT]);
  178. extern void   II_combine_LR(double[2][3][SCALE_BLOCK][SBLIMIT],
  179.                            double[3][SCALE_BLOCK][SBLIMIT], int);
  180. extern void   I_scale_factor_calc(double[][3][SCALE_BLOCK][SBLIMIT],
  181.                            unsigned int[][3][SBLIMIT], int);
  182. extern void   II_scale_factor_calc(double[][3][SCALE_BLOCK][SBLIMIT],
  183.                            unsigned int[][3][SBLIMIT], int, int);
  184. extern void   pick_scale(unsigned int[2][3][SBLIMIT], frame_params*,
  185.                            double[2][SBLIMIT]);
  186. extern void   put_scale(unsigned int[2][3][SBLIMIT], frame_params*,
  187.                            double[2][SBLIMIT]);
  188. extern void   II_transmission_pattern(unsigned int[2][3][SBLIMIT],
  189.                            unsigned int[2][SBLIMIT], frame_params*);
  190. extern void   II_encode_scale(unsigned int[2][SBLIMIT],
  191.                            unsigned int[2][SBLIMIT],
  192.                            unsigned int[2][3][SBLIMIT], frame_params*,
  193.                            Bit_stream_struc*);
  194. extern void   I_encode_scale(unsigned int[2][3][SBLIMIT],
  195.                            unsigned int[2][SBLIMIT], frame_params*,
  196.                            Bit_stream_struc*);
  197. extern int    II_bits_for_nonoise(double[2][SBLIMIT], unsigned int[2][SBLIMIT],
  198.                            frame_params*);
  199. extern void   II_main_bit_allocation(double[2][SBLIMIT],
  200.                            unsigned int[2][SBLIMIT], unsigned int[2][SBLIMIT],
  201.                            int*, frame_params*);
  202. extern int    II_a_bit_allocation(double[2][SBLIMIT], unsigned int[2][SBLIMIT],
  203.                            unsigned int[2][SBLIMIT], int*, frame_params*);
  204. extern int    I_bits_for_nonoise(double[2][SBLIMIT], frame_params*);
  205. extern void   I_main_bit_allocation(double[2][SBLIMIT],
  206.                            unsigned int[2][SBLIMIT], int*, frame_params*);
  207. extern int    I_a_bit_allocation(double[2][SBLIMIT], unsigned int[2][SBLIMIT],
  208.                            int*, frame_params*);
  209. extern void   I_subband_quantization(unsigned int[2][3][SBLIMIT],
  210.                            double[2][3][SCALE_BLOCK][SBLIMIT], unsigned int[3][SBLIMIT],
  211.                            double[3][SCALE_BLOCK][SBLIMIT], unsigned int[2][SBLIMIT],
  212.                            unsigned int[2][3][SCALE_BLOCK][SBLIMIT], frame_params*);
  213. extern void   II_subband_quantization(unsigned int[2][3][SBLIMIT],
  214.                            double[2][3][SCALE_BLOCK][SBLIMIT], unsigned int[3][SBLIMIT],
  215.                            double[3][SCALE_BLOCK][SBLIMIT], unsigned int[2][SBLIMIT],
  216.                            unsigned int[2][3][SCALE_BLOCK][SBLIMIT], frame_params*);
  217. extern void   II_encode_bit_alloc(unsigned int[2][SBLIMIT], frame_params*,
  218.                            Bit_stream_struc*);
  219. extern void   I_encode_bit_alloc(unsigned int[2][SBLIMIT], frame_params*,
  220.                            Bit_stream_struc*);
  221. extern void   I_sample_encoding(unsigned int[2][3][SCALE_BLOCK][SBLIMIT],
  222.                            unsigned int[2][SBLIMIT], frame_params*,
  223.                            Bit_stream_struc*);
  224. extern void   II_sample_encoding(unsigned int[2][3][SCALE_BLOCK][SBLIMIT],
  225.                            unsigned int[2][SBLIMIT], frame_params*,
  226.                            Bit_stream_struc*);
  227. extern void   encode_CRC(unsigned int, Bit_stream_struc*);
  228. #else
  229. extern unsigned long  read_samples();
  230. extern unsigned long  get_audio();
  231. extern void        read_ana_window();
  232. extern void        window_subband();
  233. extern void        create_ana_filter();
  234. extern void        filter_subband();
  235. extern void        encode_info();
  236. extern double      mod();
  237. extern void        I_combine_LR();
  238. extern void        II_combine_LR();
  239. extern void        I_scale_factor_calc();
  240. extern void        II_scale_factor_calc();
  241. extern void        pick_scale();
  242. extern void        put_scale();
  243. extern void        II_transmission_pattern();
  244. extern void        II_encode_scale();
  245. extern void        I_encode_scale();
  246. extern int         II_bits_for_nonoise();
  247. extern void        II_main_bit_allocation();
  248. extern int         II_a_bit_allocation();
  249. extern int         I_bits_for_nonoise();
  250. extern void        I_main_bit_allocation();
  251. extern int         I_a_bit_allocation();
  252. extern void        I_subband_quantization();
  253. extern void        II_subband_quantization();
  254. extern void        II_encode_bit_alloc();
  255. extern void        I_encode_bit_alloc();
  256. extern void        I_sample_encoding();
  257. extern void        II_sample_encoding();
  258. extern void        encode_CRC();
  259. #endif
  260.  
  261. /* The following functions are in the file "tonal.c" */
  262.  
  263. #ifdef     PROTO_ARGS
  264. extern void        read_cbound(int, int);
  265. extern void        read_freq_band(g_ptr*, int, int);
  266. extern void        make_map(mask[HAN_SIZE], g_thres*);
  267. extern double      add_db(double, double);
  268. extern void        II_f_f_t(double[FFT_SIZE], mask[HAN_SIZE]);
  269. extern void        II_hann_win(double[FFT_SIZE]);
  270. extern void        II_pick_max(mask[HAN_SIZE], double[SBLIMIT]);
  271. extern void        II_tonal_label(mask[HAN_SIZE], int*);
  272. extern void        noise_label(mask*, int*, g_thres*);
  273. extern void        subsampling(mask[HAN_SIZE], g_thres*, int*, int*);
  274. extern void        threshold(mask[HAN_SIZE], g_thres*, int*, int*, int);
  275. extern void        II_minimum_mask(g_thres*, double[SBLIMIT], int);
  276. extern void        II_smr(double[SBLIMIT], double[SBLIMIT], double[SBLIMIT],
  277.                            int);
  278. extern void        II_Psycho_One(short[2][1152], double[2][SBLIMIT],
  279.                            double[2][SBLIMIT], frame_params*);
  280. extern void        I_f_f_t(double[FFT_SIZE/2], mask[HAN_SIZE/2]);
  281. extern void        I_hann_win(double[FFT_SIZE/2]);
  282. extern void        I_pick_max(mask[HAN_SIZE/2], double[SBLIMIT]);
  283. extern void        I_tonal_label(mask[HAN_SIZE/2], int*);
  284. extern void        I_minimum_mask(g_thres*, double[SBLIMIT]);
  285. extern void        I_smr(double[SBLIMIT], double[SBLIMIT], double[SBLIMIT]);
  286. extern void        I_Psycho_One(short[2][1152], double[2][SBLIMIT],
  287.                            double[2][SBLIMIT], frame_params*);
  288. #else
  289. extern void        read_cbound();
  290. extern void        read_freq_band();
  291. extern void        make_map();
  292. extern double      add_db();
  293. extern void        II_f_f_t();
  294. extern void        II_hann_win();
  295. extern void        II_pick_max();
  296. extern void        II_tonal_label();
  297. extern void        noise_label();
  298. extern void        subsampling();
  299. extern void        threshold();
  300. extern void        II_minimum_mask();
  301. extern void        II_smr();
  302. extern void        II_Psycho_One();
  303. extern void        I_f_f_t();
  304. extern void        I_hann_win();
  305. extern void        I_pick_max();
  306. extern void        I_tonal_label();
  307. extern void        I_minimum_mask();
  308. extern void        I_smr();
  309. extern void        I_Psycho_One();
  310. #endif
  311.  
  312. /* The following functions are in the file "psy.c" */
  313.  
  314. #ifdef     PROTO_ARGS
  315. extern void        psycho_anal(short int*, short int[1056], int, int,
  316.                            FLOAT[32], double);
  317. #else
  318. extern void        psycho_anal();
  319. #endif
  320.  
  321. /* The following functions are in the file "subs.c" */
  322.  
  323. #ifdef     PROTO_ARGS
  324. extern void        fft(FLOAT[BLKSIZE], FLOAT[BLKSIZE], FLOAT[BLKSIZE],
  325.                            FLOAT[BLKSIZE], int );
  326. #else
  327. extern void        fft();
  328. #endif
  329.  
  330. #ifndef ASM
  331. #ifdef __SASC
  332. #define ASM_A0 register __a0
  333. #define ASM_A1 register __a1
  334. #define ASM_A2 register __a2
  335. #define ASM_A3 register __a3
  336. #define ASM_A4 register __a4
  337. #define ASM_A5 register __a5
  338. #define ASM_A6 register __a6
  339. #define ASM_D0 register __d0
  340. #define ASM_D1 register __d1
  341. #define ASM_D2 register __d2
  342. #define ASM_D3 register __d3
  343. #define ASM_D4 register __d4
  344. #define ASM_D5 register __d5
  345. #define ASM_D6 register __d6
  346. #define ASM_D7 register __d7
  347. #define ASM __asm
  348. #else
  349. #define ASM_A0 __A0
  350. #define ASM_A1 __A1
  351. #define ASM_A2 __A2
  352. #define ASM_A3 __A3
  353. #define ASM_A4 __A4
  354. #define ASM_A5 __A5
  355. #define ASM_A6 __A6
  356. #define ASM_D0 __D0
  357. #define ASM_D1 __D1
  358. #define ASM_D2 __D2
  359. #define ASM_D3 __D3
  360. #define ASM_D4 __D4
  361. #define ASM_D5 __D5
  362. #define ASM_D6 __D6
  363. #define ASM_D7 __D7
  364. #define ASM
  365. #endif
  366. #endif
  367.  
  368. extern void __inline ASM ASM_FastReplace( ASM_A0 double *xk, ASM_A1 short *buffer,
  369.                                    ASM_D0 int size );
  370.  
  371.